package com.touchstone.cloudpacs.controller.tohtml;

import org.apache.http.HttpStatus;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description : 错误页配置
 * @Author : hunter
 * @Date: 2019-07-21 14:57
 * @Version: 1.0
 **/
@ApiIgnore
@Controller
public class HandleErrorController implements ErrorController {

    /**
     * 公共页
     */
    private static final String COMMON = "/common";

    @RequestMapping("/error")
    public String handleError(HttpServletRequest request) {
        //获取statusCode:401,404,500
        Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
        if (statusCode == HttpStatus.SC_NOT_FOUND) {
            //404页面
            return COMMON + "/404";
        } else {
            //500页面
            return COMMON + "/500";
        }
    }

    @Override
    public String getErrorPath() {
        return "/error";
    }
}
